package com.atgouwu.mall.search.controller;

import com.atgouwu.mall.common.utils.R;
import com.atgouwu.mall.search.service.SearchService;
import com.atgouwu.mall.search.vo.SearchParam;
import com.atgouwu.mall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;

/**
 * 搜索
 */
@RestController
@RequestMapping("search/data")
public class SearchController {
    @Autowired
    private SearchService searchService;

    //根据参数从es检索商品
    @GetMapping(value = "/list")
    public R list(SearchParam param, HttpServletRequest request) {
        param.set_queryString(request.getQueryString());
        SearchResult result = searchService.search(param);
        return R.ok().put("data", result);
    }

}
